package demo;

/**
 * 深克隆
 *
 * @author dingwen
 * @date 2021/09/19
 */
public class DeepClone implements Cloneable{
    public static void main(String[] args) throws CloneNotSupportedException {
        School school = new School("社会大学");
        School school2 = school.clone();
        school.setName("test");
        System.out.println("school2 = " + school2);
        System.out.println("school = " + school);
    }


}


class School implements Cloneable{
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public School(String name) {
        this.name = name;
    }

    @Override
    protected School clone() throws CloneNotSupportedException {
        return (School) super.clone();
    }

    @Override
    public String toString() {
        return "School{" +
                "name='" + name + '\'' +
                this.hashCode() +
                '}';
    }
}
